<div id="page">
	<div class="mod-note-title">
		<h3>新用户注册</h3>
	</div>
	<div class="content">

		<%= form_for(@user) do |f| %>
		<table class="table">
		<tr>
			<td>用户名：</td>
			<td><%= f.text_field :name, :class=>'w120', :required=>"required", :autofocus=>"autofocus" %></td>
			<td class="tip">该名称用于登陆，不能少于4个字符</td>
		</tr>
		<tr>
			<td>登录密码：</td>
			<td><%= f.password_field :pass, :class=>'w120', :required=>"required" %></td>
			<td class="tip">不能少于6个字符，请小心输入并牢记</td>
		</tr>
		<tr>
			<td>电子邮箱</td>
			<td><%= f.text_field :email, :class=>'w200', :required=>"required", :type=>'email' %></td>
			<td class="tip">用于接收注册信息，以及找回密码</td>
		</tr>
		<tr>
			<td>手机号码：</td>
			<td><%= f.text_field :mobile, :class=>'w120', :maxlength=>11, :pattern=>"[0-9]{11}" %></td>
			<td class="tip">如果您希望通过手机找回密码，请正确输入</td>
		</tr>
		<tr>
			<td>验证码：</td>
			<td><%= show_simple_captcha %></td>
			<td class="tip">为了确保您不是一个机器人，请正确输入</td>
		</tr>
		<tr>
			<td colspan="3" style="text-align:center;">
				<div id="regtip" style="display:none; text-align:left;">
					<i class="icon-remove"></i>
					<span class="label label-important"></span>
				</div>
				<%= f.submit '注册用户', :class=>'btn btn-primary btn-large', :id=>'btnReg' %> &nbsp;
				<%= f.button '重新填写', :class=>'btn btn-large', :onclick=>'__reset(); return false;' %>
			</td>
		</tr>
		</table>
		<% end %>

	</div>
</div>


<script type="text/javascript">
// 显示错误提示语
function showErr (msg) {
	$('#regtip span.label').html(msg);
	$('#regtip').show();
}

// 重置表单
function __reset(){
	$('form').get(0).reset();
	$('#regtip').hide();
}

$().ready(function(){
	// 错误提示语
	<% if(flash[:err] != nil)%>
	showErr('<%=flash[:err]%>');
	<% end %>

	// 绑定注册按钮事件
	$('#btnReg').click(function(){
		var result = true;
		var arrID = [
			['user_name', '用户名'],
			['user_pass', '登录密码'],
			['user_email', '电子邮箱'],
			['captcha', '验证码']
		];
		$(arrID).each(function(){
			var id = $(this)[0];
			var name = $(this)[1];
			var obj = $('#' + id);
			if(obj.val().length == 0) {
				showErr(name + '不能为空');
				result = false;			
				return false;
			}
		});
		return result;
	});
});
</script>
